home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 15563 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.5 KB

  1. Path: news.nask.org.pl!usenet
  2. From: flssoft@blue.maloka.waw.pl (Grzegorz (FLS))
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: help! getting EOF in the middle of the file!
  5. Date: Sat, 06 Apr 1996 16:02:11 GMT
  6. Organization: Research and Academic Computer Network
  7. Message-ID: <4k60qk$iuu@bilbo.nask.org.pl>
  8. References: <DpDL8o.6xs@cdf.toronto.edu>
  9. NNTP-Posting-Host: s113.maloka.waw.pl
  10. X-Newsreader: Forte Free Agent v0.46
  11.  
  12. On Fri, 5 Apr 1996 06:12:22 GMT, you wrote:
  13.  
  14. >I have a program that was working fine using cin, and I tried to change it so
  15. >it reads from a file.
  16.  
  17. >It was working with the exact same data file before when I used:
  18. >a.out < datafile
  19.  
  20. >now it doesn't work, see the code below:
  21.  
  22. >int x;
  23. >ifstream in_stream;
  24.  
  25. >// in_stream is open and I'm reading from it no problem. 
  26. >// I'm halfway through the input file, and in_stream.eof() == 0 right now
  27.  
  28. >x = in_stream.get();
  29.  
  30. >// now in_stream.eof() == 1
  31. >// but I haven't reached the end of the file!!
  32.  
  33. >What could be going wrong here?  Any suggestions would be greatly appreciated.
  34.  
  35. Hi Paul,
  36.  
  37. It is possible, that on input you have a binary data, and you have
  38. opened an input as a text file. The end of text file is marked with
  39. char( 26 ) character, and this character could be in middle of a file.
  40. The binary data has no end character. A function reaches the end of
  41. this file when it read all data from input.
  42. The solution (meybe) is to open an input in a binary mode.
  43.  
  44. Reagrds,
  45. Grzegorz.
  46.  
  47.  
  48.  
  49. Grzegorz
  50.  
  51. ``````````````````````````` Grzes vel Pysiak
  52. Ablue, pecte canem, canis est et permanet idem.
  53. Desunt cetera!
  54.  
  55.